package com.forever.disruptor;

import com.forever.entity.User;
import com.lmax.disruptor.RingBuffer;

public class UserEventProducer {
	private final RingBuffer<UserEvent> ringBuffer;

	public UserEventProducer(RingBuffer<UserEvent> ringBuffer) {
		this.ringBuffer = ringBuffer;
	}

	public void produce(User user) {
		long sequence = ringBuffer.next();
		try {
			UserEvent event = ringBuffer.get(sequence);
			event.setUser(user);
		} finally {
			ringBuffer.publish(sequence);
		}
	}
}
